from numpy.core.numeric import NaN
import requests
import json
import pandas as pd
base_url = "http://127.0.0.1:8000/"

def post_data(api_url=None,name=None):
    if api_url is None and name is None:
        print("请输入名称和apiurl")
        return False
    url_=base_url+api_url

    payload = json.dumps({
        "name": name
    })
    headers = {
        'Content-Type': 'application/json'
    }

    response = requests.request("POST", url_, headers=headers, data=payload)

    print(response.text)


def post_data2(api_url=None,name=None,code=None):
    if api_url is None and name is None:
        print("请输入名称和apiurl")
        return False
    url_=base_url+api_url
    data_dict={"name":name}
    if code is not None:
        data_dict['code']=code

    payload = json.dumps(data_dict)
    headers = {
        'Content-Type': 'application/json'
    }

    print(payload)
    response = requests.request("POST", url_, headers=headers, data=payload)

    print(response.text)

# 风格
style_api="indicators/style_api/"
#概念
concept_api="indicators/concept_api/"
# 指数
exponent_api="indicators/exponent_api/"
#证监会行业
csrc_api="indicators/csrc_api/"
#通达信证监会行业
tdxscrc_api="indicators/tdxcsrc_api/"
# 通达信1级行业
tdx1ind_api="indicators/tdx1ind_api/"
#通达信二级行业
tdx2ind_api="indicators/tdx2ind_api/"
#地区
district_api="indicators/district_api/"

"""
style_data=pd.read_csv('../out/styles/沪深A股_风格names.csv',encoding='utf-8')
for i in style_data['风格']:
    post_data(api_url=style_api,name=i)
    print(i)
"""
"""
concept_data=pd.read_csv('../out/concept/沪深A股_概念names.csv',encoding='utf-8')
for i in concept_data['概念']:
    post_data(api_url=concept_api,name=i)
    print(i)

"""
"""
tdx1ind_data=pd.read_csv('../out/tdx_1ind/沪深A股_通达信一级行业names.csv',encoding='utf-8')
for i in tdx1ind_data['一级行业']:
    post_data(api_url=tdx1ind_api,name=i)
    print(i)
"""
"""
tdxcsrc_data=pd.read_csv('../out/tdx_csrc_ind/沪深A股_通达信证监会行业names.csv',encoding='utf-8')
for i in tdxcsrc_data['证监会行业']:
    post_data(api_url=tdxscrc_api,name=i)
    print(i)
"""
"""
csrc_data=pd.read_csv('../out/csrc/证监会行业分类代码2021.csv',encoding='gbk')
for i in csrc_data['行业大类']:
    post_data(api_url=csrc_api,name=i)
    print(i)
"""
"""
district_data=pd.read_csv('../out/district/地区names.csv',encoding='gbk')
for i in district_data['名称']:
    post_data(api_url=district_api,name=i)
    print(i)
"""
"""
tdx2ind_data=pd.read_csv('../out/tdx2_ind/通达信二级行业names.csv',encoding='gbk')
for i in tdx2ind_data['名称']:
    post_data(api_url=tdx2ind_api,name=i)
    print(i)
"""
"""
exponent_data=pd.read_csv('../out/exponent/沪深A股_指数names.csv',encoding='gbk')
exponent_data.fillna(0,inplace=True)
for i in exponent_data.index:

    if exponent_data['代码'][i]:
        post_data2(api_url=exponent_api,name=exponent_data['名称'][i],code=exponent_data['代码'][i])
    else:
        post_data2(api_url=exponent_api,name=exponent_data['名称'][i])
"""
